package cn.tedu._05mvcboot01.controller;

import cn.tedu._05mvcboot01.controller.pojo.UpdateDTO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

@RestController
public class CartsController {
    @RequestMapping("/v1/carts/addProduct")
    @ResponseBody
    public String ass() {
        return "添加成功";
    }

    public String abbProduct(HttpServletRequest request) {
        String title = request.getParameter("title");
        String price = request.getParameter("price");
        return "添加成功" + title + "---" + price;

    }

    /*
    方式:2
    http://localhost:8080/v1/carts/delete?username=???&id=666
    /v1/carts/delete
    方法:GET
     */
    @RequestMapping("/v1/carts/delete")
    @ResponseBody
    public String deleteProduct(String username, Integer id) {
        return "恭喜你" + username + "删除成功" + id;

    }

    /**
     * 方式3
     */
    @RequestMapping("/v1/carts/update")
    @ResponseBody
    public String updateProduct(UpdateDTO updateDTO) {
        String title = updateDTO.getTitle();
        Double price = updateDTO.getPrice();
        Integer namber = updateDTO.getNamber();

        return "更新成功:" + title + price + namber;

    }


}
